package com.baidu.location;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import java.util.ArrayList;
import java.util.Iterator;

final class l
{
  private static String a = "baidu_location_service";
  private ArrayList b = null;
  private Handler c = null;
  private boolean d = false;
  private boolean e = false;

  public l(Handler paramHandler)
  {
    this.c = paramHandler;
    this.b = new ArrayList();
  }

  private m a(Messenger paramMessenger)
  {
    m localm;
    if (this.b == null)
      return null;
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
    {
      localm = (m)localIterator.next();
      if (localm.b.equals(paramMessenger))
        return localm;
    }
    return null;
  }

  private void d()
  {
    int k = 0;
    Iterator localIterator = this.b.iterator();
    int i = 0;
    int j = 0;
    if (localIterator.hasNext())
    {
      label15: m localm = (m)localIterator.next();
      if (localm.c.c)
        j = 1;
      if (!(localm.c.h))
        break label175;
      i = 1;
    }
    while (true)
    {
      break label15:
      ak.a = i;
      if (this.d != j)
      {
        this.d = j;
        this.c.obtainMessage(52).sendToTarget();
      }
      localIterator = this.b.iterator();
      for (i = k; localIterator.hasNext(); i = 1)
        if (!(((m)localIterator.next()).c.f.equals("kuikedefancaiburudashahaochi")));
      if (this.e != i)
      {
        this.e = i;
        this.c.obtainMessage(81).sendToTarget();
      }
      c();
      label175: return;
    }
  }

  public final void a(Message paramMessage)
  {
    if ((paramMessage == null) || (paramMessage.replyTo == null))
    {
      ak.e();
      return;
    }
    paramMessage = new m(this, paramMessage);
    if (a(paramMessage.b) != null)
      m.a(paramMessage, 14);
    while (true)
    {
      d();
      return;
      this.b.add(paramMessage);
      new StringBuilder().append(paramMessage.a).append(" registered ");
      ak.e();
      m.a(paramMessage, 13);
    }
  }

  public final void a(String paramString)
  {
    Object localObject = new ArrayList();
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
    {
      m localm = (m)localIterator.next();
      localm.a(paramString);
      if (localm.d <= 4)
        continue;
      ((ArrayList)localObject).add(localm);
    }
    if (((ArrayList)localObject).size() <= 0)
      return;
    paramString = ((ArrayList)localObject).iterator();
    while (paramString.hasNext())
    {
      localObject = (m)paramString.next();
      ak.e();
      this.b.remove(localObject);
    }
  }

  public final void a(String paramString, int paramInt)
  {
    Object localObject = new ArrayList();
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
    {
      m localm = (m)localIterator.next();
      localm.a(paramString, paramInt);
      if (localm.d <= 4)
        continue;
      ((ArrayList)localObject).add(localm);
    }
    if (((ArrayList)localObject).size() <= 0)
      return;
    paramString = ((ArrayList)localObject).iterator();
    while (paramString.hasNext())
    {
      localObject = (m)paramString.next();
      ak.e();
      this.b.remove(localObject);
    }
  }

  public final void a(String paramString, Message paramMessage)
  {
    if ((paramString == null) || (paramMessage == null));
    do
    {
      return;
      paramMessage = a(paramMessage.replyTo);
      if (paramMessage == null)
        break label45;
      paramMessage.a(paramString);
    }
    while (paramMessage.d <= 4);
    this.b.remove(paramMessage);
    return;
    label45: ak.e();
  }

  public final boolean a()
  {
    return this.d;
  }

  public final String b()
  {
    Object localObject = new StringBuffer(256);
    m localm = (m)this.b.get(0);
    if (localm.c.f != null)
      ((StringBuffer)localObject).append(localm.c.f);
    if (localm.a != null)
    {
      ((StringBuffer)localObject).append(":");
      ((StringBuffer)localObject).append(localm.a);
      ((StringBuffer)localObject).append("|");
    }
    localObject = ((StringBuffer)localObject).toString();
    if ((localObject != null) && (!(((String)localObject).equals(""))))
      return "&prod=" + ((String)localObject);
    return ((String)null);
  }

  public final void b(Message paramMessage)
  {
    paramMessage = a(paramMessage.replyTo);
    if (paramMessage != null)
    {
      new StringBuilder().append(paramMessage.a).append(" unregistered");
      ak.e();
      this.b.remove(paramMessage);
    }
    d();
  }

  public final void b(String paramString)
  {
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
      ((m)localIterator.next()).b(paramString);
  }

  public final void c()
  {
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
      ((m)localIterator.next()).a();
  }

  public final boolean c(Message paramMessage)
  {
    int j = 1;
    m localm = a(paramMessage.replyTo);
    if (localm == null)
      return false;
    int i = localm.c.d;
    localm.c.d = paramMessage.getData().getInt("scanSpan", localm.c.d);
    if (localm.c.d < 1000)
    {
      ak.i = false;
      if ((localm.c.d <= 999) || (i >= 1000))
        break label322;
    }
    while (true)
    {
      localm.c.c = paramMessage.getData().getBoolean("openGPS", localm.c.c);
      String str = paramMessage.getData().getString("coorType");
      k localk = localm.c;
      if ((str != null) && (!(str.equals(""))))
      {
        localk.a = str;
        str = paramMessage.getData().getString("addrType");
        localk = localm.c;
        if ((str == null) || (str.equals("")))
          break label309;
      }
      while (true)
      {
        while (true)
        {
          while (true)
          {
            localk.b = str;
            ak.g = localm.c.b;
            localm.c.e = paramMessage.getData().getInt("timeOut", localm.c.e);
            localm.c.h = paramMessage.getData().getBoolean("location_change_notify", localm.c.h);
            localm.c.g = paramMessage.getData().getInt("priority", localm.c.g);
            d();
            return j;
            ak.i = true;
          }
          str = localm.c.a;
        }
        label309: str = localm.c.b;
      }
      label322: j = 0;
    }
  }

  public final String d(Message paramMessage)
  {
    m localm;
    Message localMessage = null;
    if ((paramMessage == null) || (paramMessage.replyTo == null))
      ak.e();
    do
    {
      do
      {
        return localMessage;
        localm = a(paramMessage.replyTo);
      }
      while (localm == null);
      localm.c.m = paramMessage.getData().getInt("num", localm.c.m);
      localm.c.l = paramMessage.getData().getFloat("distance", localm.c.l);
      localm.c.k = paramMessage.getData().getBoolean("extraInfo", localm.c.k);
      localm.c.j = true;
      paramMessage = String.format("&poi=%.1f|%d", new Object[] { Float.valueOf(localm.c.l), Integer.valueOf(localm.c.m) });
      localMessage = paramMessage;
    }
    while (!(localm.c.k));
    return paramMessage + "|1";
  }

  public final int e(Message paramMessage)
  {
    if ((paramMessage == null) || (paramMessage.replyTo == null));
    do
    {
      return 1;
      paramMessage = a(paramMessage.replyTo);
    }
    while ((paramMessage == null) || (paramMessage.c == null));
    return paramMessage.c.g;
  }
}